package com.example.cslp.controller;




import com.example.cslp.pojo.entity.Comment;
import com.example.cslp.service.CommentService;
import com.example.cslp.util.TimeUtil;
import com.example.cslp.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    TimeUtil timeUtil=new TimeUtil();
//    添加新评论
    @PostMapping("/addComment")
    public ResponseEntity<Boolean> addComment(@RequestBody Comment comment){
        //注入评论时间
        comment.setTime(timeUtil.getCurrentTimePlus());
        return commentService.addComment(comment);
    }
//@PostMapping("/addComment")
//public ResponseEntity<Boolean> addComment(@RequestBody Comment new_comment){
//    return commentService.addComment(new_comment);
//}
    //删除评论
    @RequestMapping("/deleteComment")
    public JsonResult deleteComment(@RequestParam String id){
        return JsonResult.ok(commentService.deleteComment(id),"评论删除成功");
    }

    //查询某门课程的评论
    @RequestMapping("/queryComment")
    public JsonResult queryComment(@RequestParam Integer c_id){
        return JsonResult.ok(commentService.queryComment(c_id),"评论查询结果");
    }

    //评论点赞
    @RequestMapping("/yesComment")
    public JsonResult yesComment(@RequestParam Integer commentId){

        return JsonResult.ok(commentService.yesComment(commentId),"点赞成功");
    }

    //评论点赞
    @RequestMapping("/noComment")
    public JsonResult noComment(@RequestParam Integer commentId){

        return JsonResult.ok(commentService.noComment(commentId),"点踩成功");
    }
}
